import React, { Component } from 'react'
import axios from 'axios'
export default class Search extends Component {
  search=()=>{
// 获取用户输入的数据
const keyWord = this.keyWordElement.value
console.log(keyWord);
this.props.updateAppState({isFirst:false,isLoading:true})
axios.get('http://localhost:3000/api1/search/users2?q='+keyWord).then((res)=>{
console.log(res.data.items);
// 在pops上有父级传过来的方法，把获取到的数据传给父级
this.props.updateAppState({isLoading:false,users:res.data.items})
}).catch((err)=>{
  this.props.updateAppState({isLoading:false,err:err.message})

})
  }
  render() {
    return (
        <section className="jumbotron">
        <h3 className="jumbotron-heading">搜索用户</h3>
        <div>
          <input type="text" placeholder="请输入" ref={c => this.keyWordElement = c} />&nbsp;<button onClick={this.search}>搜索</button>
        </div>
      </section>
    )
  }
}
